package com.shuyuwl.core.utils;

import com.shuyuwl.core.support.ServerResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

/**
 * 校验工具
 *
 * @author liaokx
 * @date 2019/12/2 11:04
 */
@Slf4j
public class ValidationUtil {

    public static ServerResponse errorShow(BindingResult result){
        String msg = "";
        for (ObjectError error : result.getAllErrors()) {
            log.error(error.getDefaultMessage());
            msg += error.getDefaultMessage()+".";
        }
        return ServerResponse.createByErrorMessage(msg);
    }
}
